<template>
  <view class="user-order">
    <u-sticky>
      <view class="tab">
        <view class="tab-item" @click="showMemerType = true">
          <picker @change="memberPickerChange" :value="defaultIndex" :range="memTypeList" range-key="name">
            <view class="picker">
              {{memTypeList[defaultIndex].name}}<u-icon name="arrow-down-fill" color="#ccc" size="14" />
            </view>
          </picker>
        </view>
        <view class="tab-item" @click="showMemerType = true">
          <picker mode="date" :value="date" @change="dateChange">
            <view class="picker">
              {{ $t("member.daoQiRq") }} {{date}}<u-icon name="arrow-down-fill" color="#ccc" size="14" />
            </view>
          </picker>
        </view>
      </view>
    </u-sticky>
    <view class="member-wrap">
      <view class="member-item" v-for="item in memerList" :key="item.id">
        <image :src="item.url" class="member-img-bg"  />
        <view class="member-content">
          <view class="top">
            <view class="top-img">
              <image :src="item.avatarUrl" class="avatar-img" />
            </view>
            <view class="top-info">
              <view class="name">{{ item.username }} <text class="type" :class="{'blue':item.level === 3,'yellow':item.level === 2}">{{ item.cardName }}</text></view>
              <view class="text">{{item.gender ==1?'男':'女'}}｜{{item.age}}{{ $t("member.sui") }}｜{{ item.phone }}</view>
            </view>
          </view>
          <view class="bottom">
            <view class="bottom-item">
              <view>{{ $t("member.jiHuoRq") }}</view>
              <view>{{ item.createTime }}</view>
            </view>
            <view class="bottom-item">
              <view>{{ $t("member.daoQiRq") }}</view>
              <view>{{ item.effectiveTime }}</view>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  computed: {
    imgPath() {
      return this.$config.baseURL + "/static/front";
    },
  },
  data() {
    return {
      showMemerType: false,
      txnStatus: "0",
      defaultIndex: '0',
      date: "",
      memTypeList: [],
      memerList: [],
      pageNum: 1,
      pageSize: 5,
      totalCount: 0,
    };
  },
  onLoad() {
    this.getcomboxList();
    // this.getMemerList();
  },
  onShow() {
    uni.setNavigationBarTitle({
      title: this.$t("page.woDeHy"),
    });
  },
  onReachBottom() {
    //上拉到底时触发，onReachBottom函数跟生命周期同级
    if (this.memerList.length < this.totalCount) {
      this.pageNum++; //当前条数小于总条数 则增加请求页数
      this.getMemerList(); //调用加载数据方法
    } else {
      uni.$u.toast(this.$t("index.yiJiaZaiQb"));
    }
  },
  methods: {
    async getcomboxList() {
      const res = await this.$api.comboxList({});
      if (res.code === 0) {
        const obj = {
          code: "",
          name: this.$t("member.quanBu"),
        };
        this.memTypeList = [obj, ...res.data.cardType];
        this.getMemerList();
      }
    },
    async getMemerList() {
      const params = {
        endTime: this.date,
        level: this.memTypeList[this.defaultIndex].code,
        pageNum: 1,
        pageSize: 5,
      };
      const res = await this.$api.getChildUser(params);
      if (res.code === 0) {
        this.memerList = [...res.data.list, ...this.memerList];
        this.totalCount = res.data.totalCount;
      } else {
        this.memerList = [];
        this.totalCount = 0;
      }
    },
    memberPickerChange(e) {
      this.defaultIndex = e.detail.value;
      this.memerList = [];
      this.getMemerList();
    },
    dateChange(e) {
      this.date = e.detail.value;
      this.memerList = [];
      this.getMemerList();
    },
  },
};
</script>
<style>
page {
  background-color: #f6f6f6;
}
</style>

<style lang="scss" scoped>
.user-order {
  // overflow: hidden;  设置后吸顶效果失效
  width: 100%;
  .tab {
    height: 50px;
    background-color: #fff;
    display: flex;
    align-items: center;
    .tab-item {
      flex: 1;
      overflow: hidden;
      display: flex;
      justify-content: center;
      font-size: 14px;
      .picker {
        display: flex;
      }
    }
  }
  .member-wrap {
    padding: 20px 0;
    overflow: hidden;
    .member-item {
      width: 100%;
      height: 165px;
      overflow: hidden;
      position: relative;
      border-radius: 12px;
      .member-img-bg {
        width: calc(100% - 20px);
        height: 165px;
        position: absolute;
        left: 10px;
        z-index: 0;
      }
      .member-content {
        position: absolute;
        left: 30px;
        top: 0;
        width: calc(100% - 60px);
        z-index: 1;
        .top {
          height: 80px;
          overflow: hidden;
          display: flex;
          align-items: center;
          border-bottom: 1px solid #ededed;
          .top-img {
            width: 48px;
            height: 48px;
            border-radius: 50%;
            overflow: hidden;
            .avatar-img {
              width: 100%;
              height: 100%;
              border-radius: 50%;
            }
          }
          .top-info {
            flex: 1;
          }
          .name {
            padding-left: 10px;
            font-size: 14px;
            margin-top: 5px;
            font-weight: bold;
            color: #333;
          }
          .type {
            font-size: 12px;
            border: 1px solid #63b0ff;
            color: #63b0ff;
            margin-left: 10px;
            padding: 0 5px;
            border-radius: 5px;
            font-weight: normal;
          }
          .yellow {
            color: #ffa836;
            border-color: #ffa836;
          }
          .blue {
            color: #3fdaff;
            border-color: #3fdaff;
          }
          .text {
            color: #999;
            font-size: 14px;
            margin-left: 10px;
            margin-top: 5px;
            letter-spacing: 1px;
          }
        }
        .bottom {
          height: 50px;
          overflow: hidden;
          display: flex;
          margin-top: 10px;
          .bottom-item {
            flex: 1;
            align-items: center;
            font-size: 13px;
            text-align: center;
            view {
              color: #333;
              line-height: 22px;
            }
          }
          .bottom-item:last-child {
            border-left: 1px solid #ededed;
          }
        }
      }
    }
  }
}
</style>
